package com.itheima.search.controller;


import com.hmall.common.dto.ItemDoc;
import com.hmall.common.pojo.RequestParams;
import com.itheima.search.service.SearchService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hmall.common.dto.PageDTO;
import java.util.List;
import java.util.Map;

@Log4j2
@RestController
@RequestMapping("search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    @GetMapping("suggestion")
    public List<String> suggestion(@RequestParam("key") String prefix) {
        return searchService.listSuggestion(prefix);
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> list (@RequestBody RequestParams requestParams){
        log.info("前后端贯通{}",requestParams);
        return searchService.list(requestParams);
    }
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams requestParams){
        return searchService.getFilters(requestParams);
    }
}
